import { defineStore } from 'pinia'
import { ref } from 'vue'
import { getCategoryPanelApi } from "@/api/category/index.ts";
import type { CategoryVo } from '@/api/category/types.ts';

// 定义 Store
export const useCategoryStore = defineStore(
  'category',
  () => {
    // 商品分类
    const categories = ref<CategoryVo[]>([]);

    /* 商品分类 */
    const getCategory = async () => {
    	const res = await getCategoryPanelApi()
    	categories.value = res.data;
    }

    // 记得 return
    return {
      getCategory,
      categories,
    }
  },
  // TODO: 网页持久化
  {
    // persist: true,
	persist: {
		// 调整为兼容多端的API
		storage:{
			getItem(key: any) {
				return uni.getStorageSync(key)
			},
			setItem(key: any, value: any){
				uni.setStorageSync(key,value)
			}
		}
	}
  },
)